package com.ita.jmsmain;

import java.io.File;
import java.util.List;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQQueue;
import org.dom4j.DocumentException;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.ita.dom.entity.WeiBo;
import com.ita.dom.handler.WeiBoDomHandler;
import com.ita.dom.handler.WeiBoJsonHandler;

public class PubSubProducer {

	public static void main(String[] args) throws JMSException, DocumentException, JsonProcessingException {
		// TODO Auto-generated method stub
		ConnectionFactory cf=new ActiveMQConnectionFactory(
				"failover:tcp://localhost:61616");
		System.out.println(cf);
		Connection conn=cf.createConnection();
		Session session=conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
		Destination queue=new ActiveMQQueue("0719");
		MessageProducer producer=session.createProducer(queue);
		
		conn.start();
		
		WeiBoDomHandler weiBoDomHandler=new WeiBoDomHandler();
		List<WeiBo> list=weiBoDomHandler.getWeiBoList(new File("weibodata.xml"));
		WeiBoJsonHandler weiBoJsonHandler=new WeiBoJsonHandler();
		String result=weiBoJsonHandler.CreateJackson(list);
		
		TextMessage tm=session.createTextMessage(result);
		System.out.println("tm:"+tm.getText());
		producer.send(tm);
		System.out.println("msg....");
//		session.commit();
		tm.acknowledge();
		
		session.close();
		producer.close();
		conn.close();
	}

}
